{extend name="mainadmin@layouts/base" /}
{block name="main" }

<header class="header  b-b clearfix">
    <div class="page-breadcrumbs">
        <ul class="breadcrumb">
            <li>
                <i class="fa fa-ellipsis-v"></i>
                <strong>{$row['pay_id']>0?'编缉支付':'添加支付'}</strong>
            </li>
        </ul>
        <a class="text-muted pull-right m-r-tm m-t-md pointer" data-toggle="back" title="返回"><i class="fa fa-reply"></i></a>
    </div>
</header>
<form class="form-horizontal form-validate form_vbox" method="post" action="{:url('info')}">
    <section class="vbox">
        <section class="scrollable  wrapper w-f">
            <section class="panel panel-default">
                <div class="panel-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">支付方式：</label>
                        <div class="col-sm-10">
                            <span class="help-inline">{$row.pay_name}</span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">接口类名：</label>
                        <div class="col-sm-10">
                            <span class="help-inline">{$row.pay_code}</span>
                        </div>
                    </div>
                    {if $row.pay_code == 'weixin' || $row.pay_code == 'weixin2'}

                    <div class="form-group">
                        <label class="col-sm-2 control-label">商户类型：</label>
                        <div class="col-sm-10">
                            <label>
                                <input type="radio" name="pay_config[mch_type]" {$row['pay_config']['mch_type'] <= 1?'checked':''}
                                value="1">普通商户
                            </label>
                            <label>
                                <input type="radio" name="pay_config[mch_type]" {$row['pay_config']['mch_type'] == 2?'checked':''}
                                value="2">服务商
                            </label>
                        </div>
                    </div>
                    <div class="mch-box">
                        <!-- <div class="form-group">
                            <label class="col-sm-2 control-label">绑定支付的APPID：</label>
                            <div class="col-sm-10">
                                <input type="text" class="input-xlarge" data-rule-required="true" name="pay_config[appid]" value="{$row['pay_config']['appid']}" aria-required="true">
                                <span class="maroon">*</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">商户号：</label>
                            <div class="col-sm-10">
                                <input type="text" class="input-xlarge" data-rule-required="true" name="pay_config[mchid]" value="{$row['pay_config']['mchid']}" aria-required="true">
                                <span class="maroon">*</span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">商户支付密钥：</label>
                            <div class="col-sm-10">
                                <input type="text" class="input-xlarge" data-rule-required="true" name="pay_config[key]" value="{$row['pay_config']['key']}" aria-required="true">
                                <span class="maroon">*</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">公众帐号secert：</label>
                            <div class="col-sm-10">
                                <input type="text" class="input-xlarge" name="pay_config[appsecret]" value="{$row['pay_config']['appsecret']}">
                                <span class="help-inline">（仅JSAPI支付的时候需要配置)</span>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">服务商商户号：</label>
                            <div class="col-sm-10">
                                <input type="text" class="input-xlarge" name="pay_config[smchid]" value="{$row['pay_config']['smchid']}">
                                <span class="help-inline">企业在线付款需用到</span>
                            </div>
                        </div>       -->
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">支付类型：</label>
                        <div class="col-sm-10">
                            <label><input type="checkbox" name="pay_config[support][]" {:in_array('JSAPI',$row['pay_config']['support'])?'checked':''} value="JSAPI"></span>JSAPI支付</label>
                            <label><input type="checkbox" name="pay_config[support][]" {:in_array('H5',$row['pay_config']['support'])?'checked':''} value="H5">H5支付</label>
                            <label><input type="checkbox" name="pay_config[support][]" {:in_array('miniAppPay',$row['pay_config']['support'])?'checked':''} value="miniAppPay">小程序</label>
                        </div>
                    </div>


                    {else}
                    {volist name="row.def_config" id="prow"}
                    <div class="form-group">
                        <label class="col-sm-2 control-label">{$prow['label']}：</label>
                        <div class="col-sm-10">
                            {if condition="$prow['type'] == 'file'"}
                            <div class="controls ">
                                <img class="thumb_img" name="imagefile" src="{$row['pay_config'][$prow['name']]}"
                                     style="max-height: 100px;"/>
                                <input class="hide" type="text" name="pay_config[{$prow['name']}]"
                                       value="{$row['pay_config'][$prow['name']]}"/>
                                <button class="btn btn-default" type="button" data-toggle="selectimg"
                                        data-config="selectimg">选择图片
                                </button>
                                <div style="color:red;margin-top:0.5rem">(请上传500*500的图片)</div>
                            </div>
                            {elseif condition="$prow['type'] == 'select'"/}
                            <select name="pay_config[{$prow['name']}]">
                                {volist name="prow.option" id="val" key='k'}
                                <option value="{$index}" {$row[
                                'pay_config'][$prow['name']]==$index?'selected':''}>{$val}</option>
                                {/volist}
                            </select>
                            {elseif condition="$prow['type'] == 'checkbox'"/}
                            {volist name="prow.option" id="val" key='k'}
                            <label><input type="checkbox" name="pay_config[{$prow['name']}][]" {:in_array($val['value'],$row['pay_config']['support'])?'checked':''}
                                value="{$val.value}">{$val.name}</label>
                            {/volist}
                            {elseif condition="$prow['type'] == 'textarea'"/}
                            <textarea name="pay_config[{$prow['name']}]" {$prow['is_must']==1?'data-rule-required="true"':''}
                            style="width:80%; height:130px;">{$row['pay_config'][$prow['name']]}</textarea>
                            {else/}
                            <input type="text" class="input-xlarge" {$prow['is_must']==1?'data-rule-required="true"':''}
                            name="pay_config[{$prow['name']}]" value="{$row['pay_config'][$prow['name']]}"/>
                            {/if}
                            {if condition="$prow['is_must'] == 1"/}
                            <span class="maroon">*</span>
                            {/if}
                            {notempty name="$prow['tip']"/}
                            <span class="help-inline">{$prow['tip']|raw}</span>
                            {/notempty}
                        </div>
                    </div>
                    {/volist}
                    {/if}
                    <div class="form-group">
                        <label class="col-sm-2 control-label">排序（升序）：</label>
                        <div class="col-sm-10">
                            <input name="sort_order" class="input-mini " value="0" type="text">
                            <span class="help-inline">数值越大排越前</span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">是否启用：</label>
                        <div class="col-sm-10">
                            <label class="radio-inline">
                                <input name="status" value="1" {$row['status']==1?'checked':''} type="radio">启用
                            </label>
                            <label class="radio-inline" title="买家在下单时将无法使用此支付方式进行付款">
                                <input name="status" value="0" {$row['status']==0?'checked':''} type="radio">不启用
                            </label>
                        </div>
                    </div>
                    <!-- <div class="form-group">
                        <label class="col-sm-2 control-label">用于充值：</label>
                        <div class="col-sm-10">
                            <label class="radio-inline">
                                <input name="is_recharge" value="1" {$row['is_recharge']==1?'checked':''} type="radio">是
                            </label>
                            <label class="radio-inline">
                                <input name="is_recharge" value="0" {$row['is_recharge']==0?'checked':''}
                                type="radio">不是
                            </label>
                        </div>
                    </div> -->
                </div>
            </section>
        </section>
        <footer class="footer bg-white b-t p-t">
            <div class="form-group">
                <div class="col-sm-4 col-sm-offset-1">
                    <input name="pay_id" type="hidden" value="{$row.pay_id|intval}">
                    <button type="submit" class="btn btn-primary js_save_submit" data-loading-text="保存中...">保存</button>
                    <button type="button" class="btn btn-default" data-toggle="back">取消</button>
                </div>
            </div>
        </footer>
    </section>
</form>
{/block}
{block name="footer" }
{literal}
<script type="text/html" id="mch1Tmp">
    <div class="form-group">
        <label class="col-sm-2 control-label">绑定支付的APPID：</label>
        <div class="col-sm-10">
            <input type="text" class="input-xlarge" data-rule-required="true" name="pay_config[appid]" value="{{appid}}" aria-required="true">
            <span class="maroon">*</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">商户号：</label>
        <div class="col-sm-10">
            <input type="text" class="input-xlarge" data-rule-required="true" name="pay_config[mchid]" value="{{mchid}}" aria-required="true">
            <span class="maroon">*</span>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">商户支付密钥：</label>
        <div class="col-sm-10">
            <input type="text" class="input-xlarge" data-rule-required="true" name="pay_config[key]" value="{{key}}" aria-required="true">
            <span class="maroon">*</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">secert：</label>
        <div class="col-sm-10">
            <input type="text" class="input-xlarge" name="pay_config[appsecret]" value="{{appsecret}}">
            <span class="help-inline">（仅JSAPI支付的时候需要配置)</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">服务商商户号：</label>
        <div class="col-sm-10">
            <input type="text" class="input-xlarge" name="pay_config[smchid]" value="{{smchid}}">
            <span class="help-inline">企业在线付款需用到</span>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">上传微信证书：</label>
        <div class="col-sm-10">
            <input type="file" name="cert[]">
            <span class="help-inline">文件名一般为apiclient_cert.pem</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">上传微信证书秘钥：</label>
        <div class="col-sm-10">
            <input type="file" name="cert[]">
            <span class="help-inline">文件名一般为apiclient_key.pem</span>
        </div>
    </div>

<!--    <div class="form-group">-->
<!--        <label class="col-sm-2 control-label">微信证书：</label>-->
<!--        <div class="col-sm-10">-->
<!--            <input type="textarea" style="width: 80%;height: 80px;" name="pay_config[cert_pem]" value="{{cert_pem}}">-->
<!--            <span class="help-inline">（文件名一般为apiclient_cert.pem)</span>-->
<!--        </div>-->
<!--    </div>-->
<!--    <div class="form-group">-->
<!--        <label class="col-sm-2 control-label">微信证书秘钥：</label>-->
<!--        <div class="col-sm-10">-->
<!--            <input type="textarea" style="width: 80%;height: 80px;" name="pay_config[cert_key]" value="{{cert_key}}">-->
<!--            <span class="help-inline">（文件名一般为apiclient_key.pem)</span>-->
<!--        </div>-->
<!--    </div>-->
</script>

<script type="text/html" id="mch2Tmp">
    <div class="form-group">
        <label class="col-sm-2 control-label">APPID：</label>
        <div class="col-sm-10">
            <input type="text" class="input-xlarge" data-rule-required="true" name="pay_config[sub_appid]" value="{{sub_appid}}" aria-required="true">
            <span class="maroon">*</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">特约商户商户号：</label>
        <div class="col-sm-10">
            <input type="text" class="input-xlarge" data-rule-required="true" name="pay_config[sub_mchid]" value="{{sub_mchid}}" aria-required="true">
            <span class="maroon">*</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">特约商户Api密钥：</label>
        <div class="col-sm-10">
            <input type="text" class="input-xlarge" data-rule-required="true" name="pay_config[sub_key]" value="{{sub_key}}" aria-required="true">
            <span class="maroon">*</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">服务商AppId：</label>
        <div class="col-sm-10">
            <input type="text" class="input-xlarge" data-rule-required="true" name="pay_config[appid]" value="{{appid}}" aria-required="true">
            <span class="maroon">*</span>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-2 control-label">服务商商户号：</label>
        <div class="col-sm-10">
            <input type="text" class="input-xlarge" data-rule-required="true" name="pay_config[mchid]" value="{{mchid}}" aria-required="true">
            <span class="maroon">*</span>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label">服务商Api密钥：</label>
        <div class="col-sm-10">
            <input type="text" class="input-xlarge" data-rule-required="true" name="pay_config[key]" value="{{key}}" aria-required="true">
            <span class="maroon">*</span>
        </div>
    </div>


    <!-- <div class="form-group">
        <label class="col-sm-2 control-label">服务商商户号：</label>
        <div class="col-sm-10">
            <input type="text" class="input-xlarge" name="pay_config[smchid]" value="{{smchid}}">
            <span class="help-inline">企业在线付款需用到</span>
        </div>
    </div> -->
</script>
{/literal}
<script type="text/javascript">
    seajs.use(["dist/plupload/init.js"])

    var pay_config = {$row['pay_config']|json_encode|raw};

    $(function(){
        var mch_type = $("input[name='pay_config[mch_type]']:checked").val();
        $('.mch-box').html(template('mch'+mch_type+'Tmp',pay_config));
        $("input[name='pay_config[mch_type]']").on('change',function(){
            mch_type = $(this).val();
            $('.mch-box').html(template('mch'+mch_type+'Tmp',[]));
        });
    })
</script>
{/block}
